<template>
  <div v-if="visible" class="custom-modal">
    <div class="modal-overlay" @click="handleCancel"></div>
    <div class="modal-content">
      <div class="modal-header">
        <h3>资产详情</h3>
        <button class="close-btn" @click="handleCancel" aria-label="关闭">×</button>
      </div>
      <div class="modal-body" v-if="assetDetail.type === '1'">
        <div class="detail-section">
          <h4 class="with-left-bar">基础信息</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in basicInfoFields1" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value" v-if="!item.isImg">{{ assetDetail[item.prop] || '-' }}</span>
              <span class="value" v-else>
                <div v-if="assetDetail[item.prop] && assetDetail[item.prop].length">
                  <j-image-upload  :disabled="true" v-model="assetDetail[item.prop]" />
                </div>
                <span v-else>-</span>
              </span>
            </div>
          </div>
        </div>
        <!-- 物理属性 section -->
        <div class="detail-section">
          <h4 class="with-left-bar">物理属性</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in physicsInfoFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">
                {{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>
        <!-- 价值和权属信息 -->
        <div class="detail-section">
          <h4 class="with-left-bar">价值和权属</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in valueInfoFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>

        <!-- 经营状况信息 -->
        <div class="detail-section">
          <h4 class="with-left-bar">经营状况</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in operationFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>

        <!-- 物业管理信息 -->
        <div class="detail-section">
          <h4 class="with-left-bar">物业管理</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in propertyFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>
        <!-- 关联设施系统 -->
        <div class="detail-section">
          <h4 class="with-left-bar">关联设施系统</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in facilityyFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}</span>
            </div>
          </div>
        </div>
        <!-- 关联文档 -->
        <div class="detail-section">
          <h4 class="with-left-bar">关联文档</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in fileFields1" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">
                <div v-if="assetDetail[item.prop] && assetDetail[item.prop].length">
                  <j-upload-view v-model="assetDetail[item.prop]" />
                </div>
                <span v-else>-</span>
              </span>
            </div>
          </div>
        </div>
        <div class="detail-section">
          <h4 class="with-left-bar">其他</h4>
          <div class="detail-grid">
            <div class="detail-item" >
              <span class="label">备注：</span>
              <span class="value">{{ assetDetail.remark || '-' }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-body" v-if="assetDetail.type === '2'">
        <div class="detail-section">
          <h4 class="with-left-bar">基础信息</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in basicInfoFields2" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}</span>
            </div>
          </div>
        </div>
        <!-- 技术规格 section -->
        <div class="detail-section">
          <h4 class="with-left-bar">技术规格</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in equipmentInfoFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">
                {{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>
        <!-- 采购与价值 -->
        <div class="detail-section">
          <h4 class="with-left-bar">采购与价值</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in purchaseValueFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>

        <!-- 维修信息 -->
        <div class="detail-section">
          <h4 class="with-left-bar">维修信息</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in maintenanceFields" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">{{ assetDetail[item.prop] || item.fallback || '-' }}
                <template v-if="item.unit && assetDetail[item.prop]">{{ item.unit }}</template>
              </span>
            </div>
          </div>
        </div>

        <!-- 关联文档 -->
        <div class="detail-section">
          <h4 class="with-left-bar">关联文档</h4>
          <div class="detail-grid">
            <div 
              class="detail-item" 
              v-for="(item, index) in fileFields2" 
              :key="index"
              v-if="item.visible"
            >
              <span class="label">{{ item.label }}：</span>
              <span class="value">
                <div v-if="assetDetail[item.prop] && assetDetail[item.prop].length">
                  <j-upload-view v-model="assetDetail[item.prop]" />
                </div>
                <span v-else>-</span>
              </span>
            </div>
          </div>
        </div>
        <div class="detail-section">
          <h4 class="with-left-bar">其他</h4>
          <div class="detail-grid">
            <div class="detail-item" >
              <span class="label">备注：</span>
              <span class="value">{{ assetDetail.remark || '-' }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button class="cancel-btn" @click="handleCancel">关闭</button>
      </div>
    </div>
  </div>
</template>

<script>
import JUploadView from '@/components/jeecg/JUploadView'
import JImageUpload from '@/components/jeecg/JImageUpload'
import { is } from 'tinymce';
export default {
  components: {
      JImageUpload,
      JUploadView
    },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    assetDetail: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // 基础信息字段
      basicInfoFields1: [
        { label: '资产编码', prop: 'assetCode', visible: true },
        { label: '资产名称', prop: 'assetName', visible: true },
        { label: '资产类型', prop: 'assetType_dictText', visible: true },
        { label: '空间类型', prop: 'spaceType_dictText', visible: true },
        { label: '空间子类', prop: 'spaceSubtype_dictText', visible: true },
        { label: '所属资产', prop: 'belongAsset_dictText', visible: true },
        { label: '所属公司', prop: 'company_dictText', visible: true },
        { label: '详细地址', prop: 'place', visible: true },
        { label: '资产状态', prop: 'status_dictText', visible: true },
        { label: '负责人', prop: 'chargePerson', visible: true },
        { label: '联系电话', prop: 'chargeMobile', visible: true },
        { label: '不动产权力人', prop: 'remainderman', visible: true },
        { label: '实物图片', prop: 'physicalImage', visible: true, isImg: true }
      ],
      basicInfoFields2: [
        { label: '资产编码', prop: 'assetCode', visible: true },
        { label: '资产名称', prop: 'assetName', visible: true },
        { label: '资产类型', prop: 'assetType_dictText', visible: true },
        { label: '设备分类', prop: 'equipmentCategory_dictText', visible: true },
        { label: '所属空间', prop: 'belongSpaceCode_dictText', visible: true },
        { label: '所属资产', prop: 'belongAsset_dictText', visible: true },
        { label: '所属公司', prop: 'company_dictText', visible: true },
        { label: '存放位置', prop: 'place', visible: true },
        { label: '资产状态', prop: 'status_dictText', visible: true },
        { label: '负责人', prop: 'chargePerson', visible: true },
        { label: '联系电话', prop: 'chargeMobile', visible: true },
        { label: '实物图片', prop: 'physicalImage', visible: true }
      ],
      // 物理属性
      physicsInfoFields: [
        { label: '建筑面积', prop: 'buildingArea', visible: true, unit: '㎡' },
        { label: '可租面积', prop: 'rentableArea', visible: true, unit: '㎡' },
        { label: '楼层信息', prop: 'floorInfo', visible: true },
        { label: '装修信息', prop: 'renovation', visible: true },
        { label: '建成日期', prop: 'completionYear', visible: true },
        { label: '停车位数量', prop: 'parkingNum', visible: true },
        { label: '电梯数量', prop: 'elevatorNum', visible: true },
        { label: '配套设施', prop: 'supportFacility', visible: true }
      ],
      // 价值和权属信息字段
      valueInfoFields: [
        { label: '权属主体', prop: 'ownershipSubject', visible: true },
        { label: '取得方式', prop: 'acquisitionMethod_dictText', visible: true },
        { label: '账面原值', prop: 'bookOriginalValue', visible: true, unit: '元' },
        { label: '账面净值', prop: 'bookNetValue', visible: true, unit: '元' },
        { label: '折旧起始年月', prop: 'depreciationStartDate', visible: true },
        { label: '月折旧额', prop: 'monthDepreciationFee', visible: true, unit: '元' },
        { label: '权证办理状态', prop: 'certificateStatus_dictText', visible: true },
        { label: '资产类型', prop: 'isFixedAsset_dictText', visible: true }
      ],

      // 经营状况字段
      operationFields: [
        { label: '经营单位', prop: 'operationUnit', visible: true },
        { label: '可否对外招租', prop: 'canRent_dictText', visible: true },
        { label: '已租面积', prop: 'rentedArea', visible: true, unit: '㎡' },
        { label: '参考租金', prop: 'referenceRent', visible: true, unit: '元/㎡/月' },
        { label: '年度收入', prop: 'annualIncome', visible: true, unit: '元' }
      ],

      // 物业管理字段
      propertyFields: [
        { label: '管理单位', prop: 'propertyCompany', visible: true },
        { label: '能源费', prop: 'energyFee', visible: true, unit: '元/月/㎡' },
        { label: '车位费', prop: 'parkingFee', visible: true, unit: '元/月' },
        { label: '物业费单价', prop: 'propertyFeeUnit', visible: true, unit: '元/月/㎡' },
        { label: '年物业费', prop: 'annualPropertyFee', visible: true, unit: '元' },
        { label: '空房管理费', prop: 'vacantManagementFee', visible: true, unit: '元' }
      ],

      //关联设施系统字段
      facilityyFields: [
        { label: '视频监控系统', prop: 'videoSurveillance', visible: true },
        { label: '门禁安防系统', prop: 'accessControl', visible: true},
        { label: '核心动转设备', prop: 'coreOperationEquipment', visible: true},
        { label: '网络情况', prop: 'networkCondition', visible: true},
        { label: '机房', prop: 'machineRoom', visible: true},
        { label: '控制室', prop: 'controlRoom', visible: true},
        { label: '设备房', prop: 'equipmentRoom', visible: true},
        { label: '其他资料', prop: 'otherData', visible: true}
      ],

      // 关联文档
      fileFields1: [
        { label: '不动产权证', prop: 'certEstateRight', visible: true },
        { label: '土地使用证', prop: 'certLandUse', visible: true},
        { label: '建设工程备案证', prop: 'certConstructionRecord', visible: true},
        { label: '规划许可证', prop: 'certPlanningPermit', visible: true},
        { label: '消防验收证', prop: 'certFireInspection', visible: true},
        { label: '环保验收证', prop: 'certEnvironmentalInspection', visible: true},
        { label: '平面图纸', prop: 'docLayoutDrawing', visible: true},
        { label: 'CAD图纸', prop: 'docCadDrawing', visible: true},
        { label: '招商资料', prop: 'docInvestment', visible: true},
        { label: '其他资料', prop: 'docOther', visible: true},
      ],


      // 技术规格
      equipmentInfoFields: [
        { label: '品牌', prop: 'brand', visible: true },
        { label: '规格型号', prop: 'model', visible: true },
        { label: '技术参数', prop: 'technicalParams', visible: true },
        { label: '制造商', prop: 'manufacturer', visible: true },
        { label: '国别', prop: 'country', visible: true },
        { label: '出厂编号', prop: 'factorySerial', visible: true },
        { label: '出厂日期', prop: 'factoryDate', visible: true }
      ],
      
      //采购与价值
      purchaseValueFields: [
        { label: '供应商', prop: 'supplier', visible: true },
        { label: '采购日期', prop: 'purchaseDate', visible: true },
        { label: '合同编号', prop: 'contractCode', visible: true },
        { label: '账面原值', prop: 'bookOriginalValue', visible: true, unit: '元' },
        { label: '账面净值', prop: 'bookNetValue', visible: true, unit: '元' },
        { label: '折旧起始年月', prop: 'depreciationStartDate', visible: true},
        { label: '保修截止日期', prop: 'warrantyEndDate', visible: true}
      ],
      
      // 维修信息字段
      maintenanceFields: [
        { label: '维修状态', prop: 'maintenanceStatus_dictText', visible: true },
        { label: '维修服务商', prop: 'maintenanceCompany', visible: true },
        { label: '维修合同', prop: 'repairContract', visible: true },
        { label: '上次维修日期', prop: 'lastMaintenanceDate', visible: true },
        { label: '下次维修日期', prop: 'nextMaintenanceDate', visible: true },
        { label: '检验日期', prop: 'inspectDate', visible: true }
      ],

      //关联文档
      fileFields2: [
        { label: '设备档案/说明', prop: 'docEquipmentFile', visible: true },
        { label: '图纸', prop: 'docDrawing', visible: true},
        { label: '权属证件', prop: 'docOwnership', visible: true},
        { label: '使用许可证', prop: 'docOperationPermit', visible: true},
        { label: '检验合格证', prop: 'docInspectionCert', visible: true},
        { label: '其他资料', prop: 'docOther', visible: true}
      ]
    };
  },
  methods: {
    handleCancel() {
      this.$emit('close');
    }
  }
};
</script>
<style scoped>
    .with-left-bar {
        position: relative;
        padding-left: 12px; /* 给竖杠留出空间 */
    }

    .with-left-bar::before {
        content: '';
        position: absolute;
        left: 0;
        top: 2px;
        bottom: 10px;
        width: 3px;
        background-color: #2a4f7a; /* 使用现有主题色中的强调色 */
        border-radius: 2px; /* 轻微圆角，更美观 */
    }

  .custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
  }
  
  .modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
  }
  
  .modal-content {
    position: relative;
    background: #0a1f44;
    border: 1px solid #1e3a5f;
    border-radius: 8px;
    width: 100%;
    max-width: 1300px;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
  }
  
  .modal-header {
    background: #102a5c;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1e3a5f;
  }
  
  .modal-header h3 {
    color: #d4e1f5;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
  }
  
  .close-btn {
    background: none;
    border: none;
    color: #8ba6d9;
    font-size: 24px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
  }
  
  .close-btn:hover {
    color: #fff;
  }
  
  .modal-body {
    padding: 20px 40px;
    overflow-y: auto;
    color: #d4e1f5;
    line-height: 1.6;
  }
  
  /* 自定义滚动条 */
  .modal-body::-webkit-scrollbar {
    width: 6px;
  }
  
  .modal-body::-webkit-scrollbar-track {
    background: #102a5c;
    border-radius: 3px;
  }
  
  .modal-body::-webkit-scrollbar-thumb {
    background: #1e3a5f;
    border-radius: 3px;
  }
  
  .modal-body::-webkit-scrollbar-thumb:hover {
    background: #2a4f7a;
  }
  
  .detail-section {
    margin-bottom: 24px;
    padding-bottom: 12px;
    /* border-bottom: 1px solid #1e3a5f; */
  }
  
  .detail-section:last-child {
    margin-bottom: 0;
    border-bottom: none;
  }
  
  .detail-section h4 {
    margin: 0 0 16px 0;
    color: #a9c4e8;
    font-size: 16px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid #1e3a5f;
  }
  
  /* 核心：动态网格布局 - 始终保持两列 */
  .detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 固定两列 */
    gap: 16px; /* 列间距 */
    row-gap: 12px; /* 行间距 */
  }
  
  /* 当字段数量为奇数时，最后一项自动占满两列 */
  .detail-grid > .detail-item:last-child:nth-child(odd) {
    grid-column: span 2;
  }
  
  .detail-item {
    display: flex;
    flex-wrap: wrap;
    padding: 4px 0;
  }
  
  .label {
    font-weight: 600;
    color: #a9c4e8;
    min-width: 100px;
    margin-right: 8px;
  }
  
  .value {
    color: #d4e1f5;
    flex: 1;
    word-break: break-word;
  }
  
  .modal-footer {
    background: #102a5c;
    padding: 14px 20px;
    border-top: 1px solid #1e3a5f;
    text-align: right;
  }
  
  .cancel-btn {
    background: #1e3a5f;
    color: #d4e1f5;
    border: 1px solid #2a4f7a;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
  }
  
  .cancel-btn:hover {
    background: #2a4f7a;
    transform: translateY(-1px);
  }
  
  .cancel-btn:active {
    transform: translateY(0);
  }
  
  /* 响应式调整 - 小屏幕自动变为单列 */
  @media (max-width: 768px) {
    .detail-grid {
      grid-template-columns: 1fr;
    }
    
    .detail-grid > .detail-item:last-child:nth-child(odd) {
      grid-column: span 1;
    }
    
    .modal-content {
      max-height: 90vh;
    }
  }
  </style>